﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Elsa.Workflows;
using Elsa.Workflows.Models;
using Newtonsoft.Json;
using T.FAS.Runtime.MF.Entity;
using T.FAS.Runtime.MF.Entity.ElsaEntity;

namespace T.FAS.Runtime.MF.Activities.ActivityInputOutput
{
    public class FasIterationExecuteDetailHandler : AbsActivityExecuteDetailHandler
    {
        public FasIterationExecuteDetailHandler(
           IActivity activity,
           ActivityExecutionRecord activityExecutionRecord,
           IEnumerable<ResolvedVariable> runtimeVariables,
           WorkflowInstance workflowInstance) : base(activity, activityExecutionRecord, runtimeVariables, workflowInstance)
        {

        }

        public override WorkflowInstanceDetail GetInputOutput()
        {
            var inputs = new Dictionary<string, object>();
            var outputs = new Dictionary<string, object>();
            var detail = new WorkflowInstanceDetail();

            var startActivity = Activity as FasStartActivity;

            if (!string.IsNullOrEmpty(ActivityExecutionRecord.SerializedActivityState))
            {
                inputs = JsonConvert.DeserializeObject<Dictionary<string,object>>(ActivityExecutionRecord.SerializedActivityState);
            }
            detail.Inputs = inputs;
            detail.Outputs = null;
            return detail;
        }
    }
}
